export class TestScene extends Phaser.Scene {
    constructor() {
        super({ key: 'TestScene' });
    }

    create() {
        // 添加背景
        this.add.rectangle(0, 0, this.game.config.width, this.game.config.height, 0x000000)
            .setOrigin(0);

        // 添加标题
        const title = this.add.text(this.game.config.width / 2, 100, '测试场景', {
            fontSize: '48px',
            fill: '#ffffff',
            fontFamily: 'Arial'
        }).setOrigin(0.5);

        // 添加测试内容说明
        const description = this.add.text(this.game.config.width / 2, 200, '这是一个用于测试功能的场景', {
            fontSize: '24px',
            fill: '#cccccc',
            fontFamily: 'Arial'
        }).setOrigin(0.5);

        // 添加一些测试元素
        // 测试按钮
        this.createTestButton(this.game.config.width / 2 - 150, 300, '测试按钮 1', () => {
            this.showTestEffect(this.game.config.width / 2 - 150, 300);
        });

        this.createTestButton(this.game.config.width / 2 + 150, 300, '测试按钮 2', () => {
            this.showTestEffect(this.game.config.width / 2 + 150, 300);
        });

        // 测试动画元素
        this.createAnimatedElement(this.game.config.width / 2, 400);

        // 返回主菜单按钮
        const backButton = this.add.text(this.game.config.width / 2, this.game.config.height - 100, '返回主菜单', {
            fontSize: '24px',
            fill: '#ffffff',
            fontFamily: 'Arial'
        })
        .setOrigin(0.5)
        .setInteractive();

        backButton.on('pointerover', () => {
            backButton.setStyle({ fill: '#ff0' });
        });

        backButton.on('pointerout', () => {
            backButton.setStyle({ fill: '#ffffff' });
        });

        backButton.on('pointerdown', () => {
            this.scene.start('MainMenuScene');
        });
    }

    createTestButton(x, y, text, callback) {
        // 创建按钮背景
        const buttonBg = this.add.rectangle(x, y, 200, 50, 0x444444, 0.8)
            .setOrigin(0.5)
            .setInteractive();

        // 创建按钮文本
        const buttonText = this.add.text(x, y, text, {
            fontSize: '20px',
            fill: '#ffffff',
            fontFamily: 'Arial'
        }).setOrigin(0.5);

        // 添加交互效果
        buttonBg.on('pointerover', () => {
            buttonBg.fillColor = 0x666666;
        });

        buttonBg.on('pointerout', () => {
            buttonBg.fillColor = 0x444444;
        });

        buttonBg.on('pointerdown', () => {
            buttonBg.fillColor = 0x888888;
            callback();
        });

        return { bg: buttonBg, text: buttonText };
    }

    showTestEffect(x, y) {
        // 创建一个简单的动画效果
        const circle = this.add.circle(x, y, 10, 0xffff00);
        
        this.tweens.add({
            targets: circle,
            scale: 5,
            alpha: 0,
            duration: 1000,
            onComplete: () => {
                circle.destroy();
            }
        });

        // 显示测试文本
        const effectText = this.add.text(x, y - 50, '测试效果!', {
            fontSize: '24px',
            fill: '#ffff00'
        }).setOrigin(0.5);

        this.tweens.add({
            targets: effectText,
            y: y - 100,
            alpha: 0,
            duration: 1500,
            onComplete: () => {
                effectText.destroy();
            }
        });
    }

    createAnimatedElement(x, y) {
        // 创建一个简单的动画元素
        const box = this.add.rectangle(x, y, 100, 100, 0xff0000)
            .setOrigin(0.5);

        // 添加持续动画
        this.tweens.add({
            targets: box,
            angle: 360,
            duration: 3000,
            repeat: -1
        });

        this.tweens.add({
            targets: box,
            scale: 1.2,
            duration: 1500,
            yoyo: true,
            repeat: -1
        });

        return box;
    }
}